local log    = require("modules.commhm.log")
local uu  = require("modules.commhm.utils")
local env     = require("modules.env.env")
local config  = require("modules.business_common.config.config" .. env.debug)
local http   = require("modules.business_common.utils.business_http")

local ngx     = ngx
local math    = math
local math_random = math.random


local FOO = {
    _VERSION       = '0.12.1',
}


-- 向CDK配置服查询银享卡的配置
FOO.query_yxcard_cdk_config = function( card_id, apiid)
	local server = config.cdk_config_server[1]
	if #config.cdk_config_server > 1 then
		local index = math_random( 1, #config.cdk_config_server )
		server = config.cdk_config_server[index]
	end

    local request = { cdk_id = card_id, apiid = apiid}
    local result= uu.json2table(http.Get(server, request)) or {}
    if uu.tableIsEmpty(result) then
        return {}
    end

   if result.code ~= 200 then
        local logdata = {
            card_id = card_id,
            uin     = ngx.ctx.m_params.uin,
            result  = result,
            apiid =  apiid,
        }
        log.day_list("business_cdk", "query_yxcard_cdk_config failed ", uu.to_str(logdata))
        return {ret=result.code}
   end

    return result.data or {}
end

return FOO